package bidgetserver;


import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ClearAllProducts extends HttpServlet{
	private static final Logger log = Logger.getLogger(ClearAllProducts.class.getName());

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {

		String userName = req.getParameter("UserName");

		PersistenceManager pm = PMF.get().getPersistenceManager();

		String query = "select from "+Product.class.getName()+" where author == '"+userName+"'";
		
		List<Product> ProductsToClear = (List<Product>) pm.newQuery(query).execute();

		try{
			pm.deletePersistentAll(ProductsToClear);
		}
		finally{
			pm.close();
		}

	}

}
